package test;
import java.io.IOException;
import org.junit.Test;
import java.util.*;

import junit.framework.*;
import junit.textui.*;
import Phase1.*;
public class testCommunication extends TestCase
{
	
	private final int DEFAULT_SERVER_PORT = 3000;
	private final int DEFAULT_CLIENT_PORT = 3000;
	
	 
	@Test
	public void testEmptyCollection() 
	{
		Collection<?> collection = new ArrayList();
		assertTrue(collection.isEmpty());
		
	}
	@Test
	public void testServerRun()
	{
		Server server = new Server();
		
		assertTrue(server instanceof Server);
		assertTrue(server instanceof Thread);
	//	assertTrue(false);
		server.done();
	}
	@Test
	public void testStringMessage()
	{
		Server server = new Server(DEFAULT_SERVER_PORT);
		
		String t = new String("here is the data");
		try 
		{ 
			assertTrue(t.equals(Client.sendData("localhost", DEFAULT_CLIENT_PORT, t))); 
		} catch (IOException e) 
		{
			e.printStackTrace();
		} 
		catch (ClassNotFoundException e)
		{
			e.printStackTrace();
		}
		server.done();
		 
	}
	@Test
	public void testNullMessage()
	{
		Server server = new Server();
		
		String t = new String("here is the data");
		try 
		{ 
			assertTrue(t.equals(Client.sendData("localhost", DEFAULT_CLIENT_PORT , t)));
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
		catch (ClassNotFoundException e) 
		{
			e.printStackTrace();
		}
		server.done();
	}
	@Test
	public void testServerHalt()
	{
		Server server = new Server();
		
		try 
		{
			Client.setLinkToServer("localhost", DEFAULT_CLIENT_PORT);
		} catch (IOException e) 
		{
			e.printStackTrace();
		}
		catch (ClassNotFoundException e) 
		{
			e.printStackTrace();
		}
		
		server.done();
		
	}
	@Test
	public void testWarp()
	{
		/*Command c=new Command();
		int r=1;
		double l=34344.435;
		int[] w={1,34,2,3,5};
		Object t=w;
		int[] f=(int[])t;
		 c.warp(r);
		System.out.println(t instanceof Object);
		System.out.println(f instanceof Object);

		System.out.println(w.getClass().isArray());
		System.out.println("---"+f.toString()  );*/
	} 
}
